/*
 * Copyright (c)  2020,  DataPipeline
 * All rights reserved.
 *
 * Id:OrmErrorCode.java   2020-07-15 00:33 wanglijun
 */
package cn.datacare.orm.exception;

import java.text.MessageFormat;

/**
 * <p>
 * Title: 异常核心错误类
 * </p>
 * <p>
 * Description: 异常核心错误类
 * </p>
 * <p>
 * Copyright: Copyright (c) 2020
 * </p>
 * <p>
 * Company/Department: DataPipeline
 * </p>
 *
 * @author wanglijun
 * @version 1.0
 * @since 2020-07-15 00:33
 */

public enum OrmErrorCode implements ErrorCode {

    /***
     * 错误加载代码
     */
    ORM_LAZY_ERROR("017", "Lazy Load Error:{0},{1}"),
    ANNOTATION_DEFINE_ERROR("023", "{0}需要实现ObjectPersistBuilder或者ObjectSelectBuilder接口"),
    ANNOTATION_ENTITY_ERROR("023", "{0}的注解 {1}的value值必须是 BaseObjectBuilder子类"),
    OBJECT_INSTANCE_ERROR("009", "OBJECT_INSTANCE_ERROR"),
    SQL_EXCEPTION("001", ""),
    //表没有找到
    TABLE_NOT_EXIST("008", "table {0} not existed"),
    //dao2 接口函数 参数定义错误
    TAIL_CALL_ERROR("013", ""),
    //dao2 接口函数 参数定义错误
    ERROR_MAPPER_PARAMETER("011","不支持的Sql注解:{0},{1}"),
    ERROR_MAPPER_PARAMETER_NO_MATCH("012","{0}与实际调用参数不匹配"),
    ID_EXPECTED_ONE_ERROR("013","无法生成sql语句，缺少主键"),
    ID_NOT_FOUND("014","主键未发现,{0},检查数据库表定义或者NameConversion"),
    UN_KNOW_MAPPER_SQL_TYPE("3001","{0}请指定Sql类型"),
    UN_KNOW_MAPPER_SQL_TYPE_3002("3002","{0}请使用 SqlStatementType 指定Sql类型"),
    ERROR_MAPPER_PARAMETER_4001("4001","PageQuery查询期望参数以PageQuyer开头，或者number,number开头"),
    OBJECT_INSTANCE_ERROR_5001("5001",""),
    ID_EXPECTED_ONE_ERROR_6013("6013","有多个主键，不能自动设置"),
    ID_EXPECTED_ONE_ERROR_6014("6014","upsert方法期望只有一个主键");
    /***
     * 错误
     */
    private final String code;
    /***
     * 错误信息
     */
    private final String message;

    OrmErrorCode(String code, String message) {
        this.code = code;
        this.message = message;
    }

    /***
     * 错误代码
     * @return String String
     */
    @Override
    public String getCode() {
        return this.code;
    }

    /***
     * 异常消息
     * @return String String
     */
    @Override
    public String getMessage() {
        return this.message;
    }

    /***
     * 参数处理消息
     * @param params
     * @return String
     */
    @Override
    public String getMessage(Object... params) {
        return MessageFormat.format(this.message, params);
    }

}
